package com.heima.article.controller;

import com.heima.article.service.ApArticleService;
import com.heima.model.article.dao.ArticleDto;
import com.heima.model.article.dao.ArticleHomeDto;
import com.heima.model.article.entity.ArticleContants;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/v1/article")
public class ArticleController {

    @Resource
    private ApArticleService apArticleService;

    @PostMapping("/save")
    public ResponseResult save(@RequestBody ArticleDto dto) {
        return apArticleService.save(dto);
    }

    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto){

        return apArticleService.load(dto,ArticleContants.LOAD_TYPE_MORE);
    }

    @PostMapping("/loadmore")
    public ResponseResult loadmore(@RequestBody ArticleHomeDto dto){

        return apArticleService.load(dto, ArticleContants.LOAD_TYPE_MORE);
    }

    @PostMapping("/loadnew")
    public ResponseResult loadnew(@RequestBody ArticleHomeDto dto){

        return apArticleService.load(dto,ArticleContants.LOAD_TYPE_NEW);
    }
}
